﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using eShop.Model.MetaData;
using eShop.DataAccess;
using eShop.DataAccess.Converter;

namespace eShop.Business
{
    public class MetaDataManager
    {
        public static List<Country> GetAllCountries()
        {
            return CountryConverter.ConvertToModelObject((CountryDAL.GetAll()));
        }

        public static List<State> GetAllStates()
        {
            return StateConverter.ConvertToModelObject((StateDAL.GetAll()));
        }

        public static List<State> GetAllStatesWithCountry()
        {
            List<Country> countries = CountryConverter.ConvertToModelObject((CountryDAL.GetAll()));
            List<State> states = StateConverter.ConvertToModelObject((StateDAL.GetAll()));
            StateConverter.AttachAssociation(states, countries);
            return states;
        }

        public static List<City> GetAllCities()
        {
            return CityConverter.ConvertToModelObject((CityDAL.GetAll()));
        }

        public static List<City> GetAllCitiesWithStateAndCountry()
        {
            List<State> states = GetAllStatesWithCountry();
            List<City> cities = CityConverter.ConvertToModelObject((CityDAL.GetAll()));
            CityConverter.AttachAssociation(cities, states);
            return cities;
        }

        public static State GetStateById(int stateId)
        {
            List<State> states = StateConverter.ConvertToModelObject(StateDAL.GetByKeys(stateId, null));
            if ( states.Count>0)
                return states[0];
            return null;
        }

        public static List<State> GetAllStatesByCountry(int countryId)
        {
            return StateConverter.ConvertToModelObject(StateDAL.GetByKeys(null, countryId));
        }

        public static City GetCityById(int cityId)
        {
            List<City> cities = CityConverter.ConvertToModelObject(CityDAL.GetByKeys(cityId, null));
            if (cities.Count > 0)
                return cities[0];
            return null;
        }

        public static List<City> GetAllCitiesByState(int stateId)
        {
            return CityConverter.ConvertToModelObject(CityDAL.GetByKeys(null, stateId));
        }
    }
}
